package com.laoma.usercenter.handler;

import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.laoma.usercenter.common.CommonResponse;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class FallbackHandler {
    //对程序异常的处理
    public static CommonResponse handleFallback(String wxid, Throwable e) {
        //这里可以自定义的处理各种的异常
        if(e instanceof RuntimeException) {
            log.error(e.getMessage());
        }
        return CommonResponse.buildFailCommonResponse(String.format(e.getMessage() + "【%s】", wxid));
    }

    //对流控异常的处理
    public static CommonResponse handleBlockHandler(String wxid, BlockException e) {
        log.error("流控降级处理");
        return CommonResponse.buildFailCommonResponse("被流控或者降级了");
    }
}
